package com.jdls;

import com.jdls.config.SpringConfig;
import com.jdls.pojo.Account;
import com.jdls.service.AccountService;
import com.jdls.service.impl.AccountServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;
import java.util.List;


//【第二步】使用Spring整合Junit专用的类加载器
@RunWith(SpringJUnit4ClassRunner.class)
//【第三步】加载配置文件或者配置类
@ContextConfiguration(classes = {SpringConfig.class}) //加载配置类
//@ContextConfiguration(locations={"classpath:applicationContext.xml"})//加载配置文件
public class App {
    @Autowired
    private AccountService accountService;

    @Test
    public void testFindAll(){
        System.out.println(accountService.findAll());
    }

    @Test
    public void method(){
        ApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfig.class);
        AccountService bean = ac.getBean(AccountService.class);
        bean.findAll();
    }

    @Test
    public void testTransfer() throws IOException {
        accountService.transfer("张三","李四",100D);
    }

}